package com.bw.finance.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bw.finance.conf.ResponseResult;
import com.bw.finance.eneity.locana.EbankLoanInfo;
import com.bw.finance.eneity.locana.EbankRepayPlan;
import com.bw.finance.mapper.EbankRepayPlanMapper;
import com.bw.finance.service.IEbankLoanInfoService;
import com.bw.finance.service.IEbankRepayPlanService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zxx
 * @since 2020-08-27
 */
@Service
public class EbankRepayPlanServiceImpl extends ServiceImpl<EbankRepayPlanMapper, EbankRepayPlan> implements IEbankRepayPlanService {

    @Autowired
    private IEbankRepayPlanService ebankRepayPlanService;

    @Autowired
    private IEbankLoanInfoService loanInfoService;

    @Override
    public ResponseResult getRepayPlan(Long id) {
        ResponseResult result = ResponseResult.SUCCESS();
        try {
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.eq("LID",id);

            List list = ebankRepayPlanService.list(queryWrapper);
            result.setResult(list);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("查询失败!");
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public ResponseResult getRepayPlanById(Long id) {
        ResponseResult result = ResponseResult.SUCCESS();
        try {
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.eq("BORROWER_ID",id);
            List<EbankLoanInfo> list = loanInfoService.list(queryWrapper);
            System.out.println(list.toString());
            for (EbankLoanInfo ebankLoanInfo:list) {
                System.out.println("这个是这个人的id查询的借款id"+ebankLoanInfo.getId());
                ArrayList<EbankRepayPlan> planArrayList = new ArrayList<>();
                QueryWrapper wrapper = new QueryWrapper();
                wrapper.eq("LID",ebankLoanInfo.getId());
                List<EbankRepayPlan> repayList = ebankRepayPlanService.list(wrapper);
                System.out.println(repayList);
                result.setResult(repayList);
            }
            return result;
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("查询失败!");
            e.printStackTrace();
        }
        return result;
    }
}
